package com.corgi.dubbo.provider.service.impl;

import com.corgi.dubbo.api.bean.UserAddress;
import com.corgi.dubbo.api.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @title: UserServiceImpl
 * @description:
 * @org.apache.dubbo.config.annotation.Service 暴露服务
 * @author: dengmiao
 * @create: 2019-09-24 16:08
 **/
@Service
@Component
public class UserServiceImpl implements UserService {

	@HystrixCommand
	@Override
	public List<UserAddress> findList(String userId) {
		UserAddress address1 = new UserAddress()
				.setId(1)
				.setUserAddress("")
				.setUserId("")
				.setConsignee("")
				.setPhoneNum("")
				.setIsDefault("Y");
		UserAddress address2 = new UserAddress()
				.setId(2)
				.setUserAddress("")
				.setUserId("")
				.setConsignee("")
				.setPhoneNum("")
				.setIsDefault("N");
		double randomNum = Math.random();
		double threshold = 0.5;
		if(randomNum > threshold) {
			throw new RuntimeException(String.valueOf(randomNum));
		}
		return Arrays.asList(address1, address2);
	}
}
